﻿using Microsoft.AspNetCore.Authorization;

namespace Simple.WebApi.Controllers.System
{
    /// <summary>
    /// 课程分类管理
    /// </summary>
    [Route("api/CourseType/[action]")]
    [ApiController]
    [Authorize]
    public class CourseTypeController : ControllerBase
    {
        private readonly CourseTypeService _courseTypeService;

        public CourseTypeController(CourseTypeService courseTypeService)
        {
            _courseTypeService = courseTypeService;
        }

        /// <summary>
        /// 课程分类列表
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> List()
        {
            List<CourseTypeModel> data = await _courseTypeService.GetAsync();
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 课程分类查询
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<AppResult> Page([FromQuery] CourseTypePageInputModel model)
        {
            PageResultModel<CourseTypeModel> data = await _courseTypeService.GetPageAsync(model);
            return AppResult.Status200OK(data: data);
        }

        /// <summary>
        /// 课程分类增加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Add([FromBody] CourseTypeInputModel model)
        {
            await _courseTypeService.AddAsync(model);
            return AppResult.Status200OK("新增成功");
        }

        /// <summary>
        /// 课程分类编辑
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Edit([FromBody] CourseTypeInputModel model)
        {
            await _courseTypeService.UpdateAsync(model);
            return AppResult.Status200OK("更新成功");
        }

        /// <summary>
        /// 课程分类删除
        /// </summary>
        /// <param name="models"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<AppResult> Delete([FromBody] List<IdInputModel> models)
        {
            await _courseTypeService.DeleteAsync(models.Select(m => m.Id));
            return AppResult.Status200OK("删除成功");
        }
    }
}
